﻿using System;
using System.Collections.Generic;

using System.Text;
using Microsoft.Office.Interop.Excel;
using System.Runtime.CompilerServices;
using System.Data;
using Microsoft.VisualBasic.CompilerServices;
using System.Reflection;
using System.Windows.Forms;
using Microsoft.VisualBasic;
using System.Runtime.InteropServices;
using System.Drawing;

namespace QUANLYCHAMCONG.BL.BUS.Import
{
    public class Excel
    {
        #region "Khai bao bien"
        public static Microsoft.Office.Interop.Excel.Application ExApp = new Microsoft.Office.Interop.Excel.Application();
        public static Workbook TasWBook = new Workbook();
        public static Worksheet TasWSheet = new Worksheet();
        #endregion
        public System.Data.DataTable BangCong = new System.Data.DataTable();
        public System.Data.DataTable BangTong = new System.Data.DataTable();
        
        
        public void CreateBangCong_BangTong(System.Data.DataTable dtb, string UserName)
        {
            try
            {
                float num = 0;
                float num2 = 0;
                float num3 = 0;
                float num4 = 0;
                float num6 = 0;
                int num7 = 0;
                float num8 = 0;
                float num9 = 0;
                float num10 = 0;
                float num11 = 0;
                int num12 = 0;
                int num5 = 0;
                int num14 = dtb.Rows.Count - 1;
                for (int i = 0; i <= num14; i++)
                {
                    DataRow row2 = this.BangCong.NewRow();
                    row2["UserFullcode"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["MUserCode"]);
                    row2["UserFullName"] = UserName;
                    row2["Mdate"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["Mdate"]);
                    row2["Thu"] = Until.XuatThu(Conversions.ToInteger(dtb.Rows[i]["MWDay"]));
                    row2["In1"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["In1"]);
                    row2["Out1"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["Out1"]);
                    row2["In2"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["In2"]);
                    row2["Out2"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["Out2"]);
                    row2["In3"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["In3"]);
                    row2["Out3"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["Out3"]);
                    row2["MShift"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["MShift"]);
                    row2["MReg"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["MReg"]);
                    row2["MWD"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["MWD"]);
                    row2["MOT1"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["MOT1"]);
                    row2["MOT2"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["MOT2"]);
                    row2["MOT3"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["MOT3"]);
                    row2["MSym"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["MSym"]);
                    row2["MLate"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["MLate"]);
                    row2["MEarly"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["MEarly"]);
                    row2["MNTime"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["MNTime"]);
                    row2["MGTotal"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["MGTotal"]);
                    row2["MaxWorkingTime"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["MaxWorkingTime"]);
                    row2["PunchGrace"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["PunchGrace"]);
                    row2["Thaisan"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["Thaisan"]);
                    row2["TypeNo"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["TypeNo"]);
                    row2["BL"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["BL"]);
                    row2["F"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["F"]);
                    row2["IDD"] = RuntimeHelpers.GetObjectValue(dtb.Rows[i]["IDD"]);
                    this.BangCong.Rows.Add(row2);
                    num5 = Conversions.ToInteger(dtb.Rows[i]["IDD"]);
                    num4 = Conversions.ToSingle(Microsoft.VisualBasic.CompilerServices.Operators.AddObject(num4, dtb.Rows[i]["MReg"]));
                    num2 = Conversions.ToSingle(Microsoft.VisualBasic.CompilerServices.Operators.AddObject(num2, dtb.Rows[i]["MWD"]));
                    num8 = Conversions.ToSingle(Microsoft.VisualBasic.CompilerServices.Operators.AddObject(num8, dtb.Rows[i]["MOT1"]));
                    num9 = Conversions.ToSingle(Microsoft.VisualBasic.CompilerServices.Operators.AddObject(num9, dtb.Rows[i]["MOT2"]));
                    num10 = Conversions.ToSingle(Microsoft.VisualBasic.CompilerServices.Operators.AddObject(num10, dtb.Rows[i]["MOT3"]));
                    num11 = Conversions.ToSingle(Microsoft.VisualBasic.CompilerServices.Operators.AddObject(num11, dtb.Rows[i]["MGTotal"]));
                    num12 = Conversions.ToInteger(Microsoft.VisualBasic.CompilerServices.Operators.AddObject(num12, dtb.Rows[i]["MLate"]));
                    num7 = Conversions.ToInteger(Microsoft.VisualBasic.CompilerServices.Operators.AddObject(num7, dtb.Rows[i]["MEarly"]));
                    num6 = Conversions.ToSingle(Microsoft.VisualBasic.CompilerServices.Operators.AddObject(num6, dtb.Rows[i]["MNTime"]));
                    num3 = Conversions.ToSingle(Microsoft.VisualBasic.CompilerServices.Operators.AddObject(num3, dtb.Rows[i]["F"]));
                    num = Conversions.ToSingle(Microsoft.VisualBasic.CompilerServices.Operators.AddObject(num, dtb.Rows[i]["BL"]));
                }
                DataRow row = this.BangTong.NewRow();
                row["UserFullCode"] = RuntimeHelpers.GetObjectValue(dtb.Rows[0]["MUserCode"]);
                row["UserFullName"] = UserName;
                row["IDD"] = num5;
                row["SReg"] = Math.Round((double)num2, 2);
                row["STotal"] = Math.Round((double)num4, 2);
                row["SLate"] = num12;
                row["SEarly"] = num7;
                row["SOT1"] = Math.Round((double)num8, 2);
                row["SOT2"] = Math.Round((double)num9, 2);
                row["SOT3"] = Math.Round((double)num10, 2);
                row["SGTotal"] = Math.Round((double)num11, 2);
                row["SMNTime"] = Math.Round((double)num6, 2);
                row["F"] = Math.Round((double)num3, 2);
                row["BL"] = Math.Round((double)num, 2);
                this.BangTong.Rows.Add(row);
                num4 = 0f;
                num2 = 0f;
                num12 = 0;
                num6 = 0f;
                num3 = 0f;
                num7 = 0;
                num8 = 0f;
                num9 = 0f;
                num11 = 0f;
                num = 0f;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                Interaction.MsgBox("GreateBangCong_BangTong: " + exception.Message, MsgBoxStyle.Critical, null);
                ProjectData.ClearProjectError();
            }
        }
        public void TaoHeaderTre(int StartRow, DateTime TuNgay, DateTime DenNgay)
        {
            int num2 = StartRow + 3;
            Worksheet tasWSheet = TasWSheet;
            tasWSheet.get_Range("C" + Conversions.ToString((int)(num2 - 3)) + ":P" + Conversions.ToString((int)(num2 - 3)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("C" + Conversions.ToString((int)(num2 - 3)), Missing.Value).set_Value(Missing.Value, "NHÂN VIÊN ĐI TRỄ");
            tasWSheet.get_Range("C" + Conversions.ToString((int)(num2 - 3)), Missing.Value).Font.Bold = true;
            tasWSheet.get_Range("C" + Conversions.ToString((int)(num2 - 3)), Missing.Value).Font.Size = 14;
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 2)) + ":P" + Conversions.ToString((int)(num2 - 2)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 2)), Missing.Value).set_Value(Missing.Value, "Từ ng\x00e0y " + Conversions.ToString(TuNgay) + " đến ng\x00e0y " + Conversions.ToString(DenNgay));
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 2)), Missing.Value).Font.Size = 10;
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 2)), Missing.Value).Font.Bold = true;
            tasWSheet.get_Range("A" + Conversions.ToString(num2) + ":A" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("A" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "STT");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["A", Missing.Value], null, "ColumnWidth", new object[] { 4.2 }, null, null, false, true);
            tasWSheet.get_Range("B" + Conversions.ToString(num2) + ":B" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("B" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "Ph\x00f2ng ban");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["B", Missing.Value], null, "ColumnWidth", new object[] { 14 }, null, null, false, true);
            tasWSheet.get_Range("C" + Conversions.ToString(num2) + ":C" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("C" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "M\x00e3 NV");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["C", Missing.Value], null, "ColumnWidth", new object[] { 7 }, null, null, false, true);
            tasWSheet.get_Range("D" + Conversions.ToString(num2) + ":D" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("D" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "T\x00ean nh\x00e2n vi\x00ean");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["D", Missing.Value], null, "ColumnWidth", new object[] { 20 }, null, null, false, true);
            tasWSheet.get_Range("E" + Conversions.ToString(num2) + ":E" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("E" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "Chức vụ");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["E", Missing.Value], null, "ColumnWidth", new object[] { 10 }, null, null, false, true);
            tasWSheet.get_Range("F" + Conversions.ToString(num2) + ":F" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("F" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "Ng\x00e0y");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["F", Missing.Value], null, "ColumnWidth", new object[] { 10 }, null, null, false, true);
            tasWSheet.get_Range("G" + Conversions.ToString(num2) + ":G" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("G" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "Thứ");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["G", Missing.Value], null, "ColumnWidth", new object[] { 4 }, null, null, false, true);
            tasWSheet.get_Range("H" + Conversions.ToString(num2) + ":H" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("H" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "V\x00e0o 1");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["H", Missing.Value], null, "ColumnWidth", new object[] { 5.2 }, null, null, false, true);
            tasWSheet.get_Range("I" + Conversions.ToString(num2) + ":I" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("I" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "Ra 1");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["I", Missing.Value], null, "ColumnWidth", new object[] { 5.2 }, null, null, false, true);
            tasWSheet.get_Range("J" + Conversions.ToString(num2) + ":J" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("J" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "V\x00e0o 2");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["J", Missing.Value], null, "ColumnWidth", new object[] { 5.2 }, null, null, false, true);
            tasWSheet.get_Range("K" + Conversions.ToString(num2) + ":K" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("K" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "Ra 2");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["K", Missing.Value], null, "ColumnWidth", new object[] { 5.2 }, null, null, false, true);
            tasWSheet.get_Range("L" + Conversions.ToString(num2) + ":L" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("L" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "V\x00e0o 3");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["L", Missing.Value], null, "ColumnWidth", new object[] { 5.2 }, null, null, false, true);
            tasWSheet.get_Range("M" + Conversions.ToString(num2) + ":M" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("M" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "Ra 3");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["M", Missing.Value], null, "ColumnWidth", new object[] { 5.2 }, null, null, false, true);
            tasWSheet.get_Range("N" + Conversions.ToString(num2) + ":N" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("N" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "Đi trễ");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["N", Missing.Value], null, "ColumnWidth", new object[] { 4 }, null, null, false, true);
            tasWSheet.get_Range("O" + Conversions.ToString(num2) + ":O" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("O" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "Ca");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["O", Missing.Value], null, "ColumnWidth", new object[] { 4 }, null, null, false, true);
            tasWSheet.get_Range("P" + Conversions.ToString(num2) + ":P" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("P" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "K\x00ed hiệu");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["P", Missing.Value], null, "ColumnWidth", new object[] { 4 }, null, null, false, true);
            NewLateBinding.LateSetComplex(tasWSheet.Rows["5", Missing.Value], null, "RowHeight", new object[] { 0x19 }, null, null, false, true);
            tasWSheet.get_Range("A" + Conversions.ToString(num2) + ":P" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Font.Bold = true;
            tasWSheet.get_Range("A" + Conversions.ToString(num2) + ":P" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Font.Size = 8;
            tasWSheet.get_Range("A" + Conversions.ToString(num2) + ":P" + Conversions.ToString((int)(num2 + 1)), Missing.Value).HorizontalAlignment = XlHAlign.xlHAlignCenter;
            tasWSheet.get_Range("A" + Conversions.ToString(num2) + ":P" + Conversions.ToString((int)(num2 + 1)), Missing.Value).WrapText = 1;
            tasWSheet.get_Range("A" + Conversions.ToString(num2) + ":P" + Conversions.ToString((int)(num2 + 1)), Missing.Value).Borders.LineStyle = 1;
            tasWSheet.get_Range("A" + Conversions.ToString(num2) + ":P" + Conversions.ToString((int)(num2 + 1)), Missing.Value).VerticalAlignment = XlVAlign.xlVAlignCenter;
            tasWSheet = null;
        }
       
        void TaoHeaderTong(int StartRow, DateTime tungay, DateTime denngay)
        {
            int num2 = StartRow + 3;
            Worksheet tasWSheet = TasWSheet;
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 3)) + ":K" + Conversions.ToString((int)(num2 - 3)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 3)), Missing.Value).set_Value(Missing.Value, "BẢNG TỔNG C\x00d4NG");
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 3)), Missing.Value).Font.Bold = true;
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 3)), Missing.Value).Font.Size = 14;
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 2)) + ":K" + Conversions.ToString((int)(num2 - 2)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 2)), Missing.Value).set_Value(Missing.Value, "Từ ng\x00e0y " + Conversions.ToString(tungay) + " đến ng\x00e0y " + Conversions.ToString(denngay));
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 2)), Missing.Value).Font.Size = 10;
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 2)), Missing.Value).Font.Bold = true;
            tasWSheet.get_Range("A" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "STT");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["A", Missing.Value], null, "ColumnWidth", new object[] { 4.2 }, null, null, false, true);
            tasWSheet.get_Range("B" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "Ph\x00f2ng ban");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["B", Missing.Value], null, "ColumnWidth", new object[] { 14 }, null, null, false, true);
            tasWSheet.get_Range("C" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "M\x00e3 NV");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["C", Missing.Value], null, "ColumnWidth", new object[] { 7 }, null, null, false, true);
            tasWSheet.get_Range("D" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "T\x00ean nh\x00e2n vi\x00ean");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["D", Missing.Value], null, "ColumnWidth", new object[] { 20 }, null, null, false, true);
            tasWSheet.get_Range("E" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "Chức vụ");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["E", Missing.Value], null, "ColumnWidth", new object[] { 15 }, null, null, false, true);
            tasWSheet.get_Range("F" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "C\x00f4ng h\x00e0nh ch\x00e1nh");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["F", Missing.Value], null, "ColumnWidth", new object[] { 10 }, null, null, false, true);
            tasWSheet.get_Range("G" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "C\x00f4ng tăng ca");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["G", Missing.Value], null, "ColumnWidth", new object[] { 6 }, null, null, false, true);
            tasWSheet.get_Range("H" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "Tổng hợp c\x00f4ng");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["H", Missing.Value], null, "ColumnWidth", new object[] { 6 }, null, null, false, true);
            tasWSheet.get_Range("I" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "Chờ việc");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["I", Missing.Value], null, "ColumnWidth", new object[] { 6 }, null, null, false, true);
            tasWSheet.get_Range("J" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "Đếm tăng ca >2");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["J", Missing.Value], null, "ColumnWidth", new object[] { 6 }, null, null, false, true);
            tasWSheet.get_Range("K" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "C\x00f4ng Chủ nhật");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["K", Missing.Value], null, "ColumnWidth", new object[] { 6 }, null, null, false, true);
            tasWSheet.get_Range("A" + Conversions.ToString(num2) + ":K" + Conversions.ToString(num2), Missing.Value).Font.Bold = true;
            tasWSheet.get_Range("A" + Conversions.ToString(num2) + ":K" + Conversions.ToString(num2), Missing.Value).Font.Size = 8;
            tasWSheet.get_Range("A" + Conversions.ToString(num2) + ":K" + Conversions.ToString(num2), Missing.Value).HorizontalAlignment = XlHAlign.xlHAlignCenter;
            tasWSheet.get_Range("A" + Conversions.ToString(num2) + ":K" + Conversions.ToString(num2), Missing.Value).WrapText = 1;
            tasWSheet.get_Range("A" + Conversions.ToString(num2) + ":K" + Conversions.ToString(num2), Missing.Value).Borders.LineStyle = 1;
            tasWSheet.get_Range("A" + Conversions.ToString(num2) + ":K" + Conversions.ToString(num2), Missing.Value).VerticalAlignment = XlVAlign.xlVAlignCenter;

        }
       
        public void XuatLuoiDong(BindingSource bng, int dong, int Pos, int Chay)
        {
            string str = "";
            BindingSource source = bng;
            source.Position = Pos;
            TasWSheet.get_Range("A" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, Chay);
            str = Conversions.ToString(NewLateBinding.LateIndexGet(source.Current, new object[] { "UserFullName" }, null));
            string str2 = Conversions.ToString(NewLateBinding.LateIndexGet(source.Current, new object[] { "UserFullCode" }, null));
            int num = Conversions.ToInteger(NewLateBinding.LateIndexGet(source.Current, new object[] { "IDD" }, null));
          //  int num2 = 0;// Conversions.ToInteger(this.Conn.GetData("UserInfo", "UserIDTitle", Conversions.ToString(Operators.ConcatenateObject(Operators.ConcatenateObject("UserFullCode='", NewLateBinding.LateIndexGet(source.Current, new object[] { "UserFullCode" }, null)), "'")), Conversions.ToString(0)));
            string Dept = ""; //this.Conn.GetData("Dept", "Dept", "IDD=" + Conversions.ToString(num), "------");
            string Chucdanh = ""; //this.Conn.GetData("Title", "TitleName", "IDT=" + Conversions.ToString(num2), "-----");
            string MNVC = str2;
            TasWSheet.get_Range("B" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, Dept);
            TasWSheet.get_Range("C" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, Operators.ConcatenateObject("'", NewLateBinding.LateIndexGet(source.Current, new object[] { "UserFullCode" }, null)));
            TasWSheet.get_Range("D" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, str);
            TasWSheet.get_Range("E" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, Chucdanh);
            TasWSheet.get_Range("F" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "MDate" }, null)));
            TasWSheet.get_Range("G" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "Thu" }, null)));
            TasWSheet.get_Range("H" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "In1" }, null)));
            TasWSheet.get_Range("I" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "Out1" }, null)));
            TasWSheet.get_Range("J" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "In2" }, null)));
            TasWSheet.get_Range("K" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "Out2" }, null)));
            TasWSheet.get_Range("L" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "In3" }, null))); ;
            TasWSheet.get_Range("M" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "Out3" }, null)));
            TasWSheet.get_Range("N" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(Interaction.IIf(Operators.ConditionalCompareObjectEqual(NewLateBinding.LateIndexGet(source.Current, new object[] { "MReg" }, null), 0, false), "", RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "MReg" }, null)))));
            TasWSheet.get_Range("O" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(Interaction.IIf(Operators.ConditionalCompareObjectEqual(NewLateBinding.LateIndexGet(source.Current, new object[] { "MWD" }, null), 0, false), "", RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "MWD" }, null)))));
            TasWSheet.get_Range("P" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(Interaction.IIf(Operators.ConditionalCompareObjectEqual(NewLateBinding.LateIndexGet(source.Current, new object[] { "MOT1" }, null), 0, false), "", RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "MOT1" }, null)))));
            TasWSheet.get_Range("Q" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(Interaction.IIf(Operators.ConditionalCompareObjectEqual(NewLateBinding.LateIndexGet(source.Current, new object[] { "MOT2" }, null), 0, false), "", RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "MOT2" }, null)))));
            TasWSheet.get_Range("R" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(Interaction.IIf(Operators.ConditionalCompareObjectEqual(NewLateBinding.LateIndexGet(source.Current, new object[] { "MOT3" }, null), 0, false), "", RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "MOT3" }, null)))));
            TasWSheet.get_Range("S" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(Interaction.IIf(Operators.ConditionalCompareObjectEqual(NewLateBinding.LateIndexGet(source.Current, new object[] { "MLate" }, null), 0, false), "", RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "MLate" }, null)))));
            TasWSheet.get_Range("T" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(Interaction.IIf(Operators.ConditionalCompareObjectEqual(NewLateBinding.LateIndexGet(source.Current, new object[] { "MEarly" }, null), 0, false), "", RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "MEarly" }, null)))));
            TasWSheet.get_Range("U" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(Interaction.IIf(Operators.ConditionalCompareObjectEqual(Operators.AddObject(NewLateBinding.LateIndexGet(source.Current, new object[] { "MLate" }, null), NewLateBinding.LateIndexGet(source.Current, new object[] { "MEarly" }, null)), 0, false), "", Operators.AddObject(NewLateBinding.LateIndexGet(source.Current, new object[] { "MLate" }, null), NewLateBinding.LateIndexGet(source.Current, new object[] { "MEarly" }, null)))));
            TasWSheet.get_Range("V" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(Interaction.IIf(Operators.ConditionalCompareObjectEqual(NewLateBinding.LateIndexGet(source.Current, new object[] { "MNTime" }, null), 0, false), "", RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "MNTime" }, null)))));
            TasWSheet.get_Range("W" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(Interaction.IIf(Operators.ConditionalCompareObjectEqual(NewLateBinding.LateIndexGet(source.Current, new object[] { "BL" }, null), 0, false), "", RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "BL" }, null)))));
            TasWSheet.get_Range("X" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(Interaction.IIf(Operators.ConditionalCompareObjectEqual(NewLateBinding.LateIndexGet(source.Current, new object[] { "F" }, null), 0, false), "", RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "F" }, null)))));
            TasWSheet.get_Range("Y" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(Interaction.IIf(Operators.ConditionalCompareObjectEqual(NewLateBinding.LateIndexGet(source.Current, new object[] { "MGTotal" }, null), 0, false), "", RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "MGTotal" }, null)))));
            TasWSheet.get_Range("Z" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "MShift" }, null)));
            TasWSheet.get_Range("AA" + Conversions.ToString(dong), Missing.Value).set_Value(Missing.Value, RuntimeHelpers.GetObjectValue(NewLateBinding.LateIndexGet(source.Current, new object[] { "MSym" }, null)));
            source = null;
        }
        
        public void FooterXuatTre(object dong)
        {
            TasWSheet.get_Range(Operators.ConcatenateObject(Operators.ConcatenateObject(Operators.ConcatenateObject(Operators.ConcatenateObject("A", dong), ":"), "P"), dong), Missing.Value).Interior.Color = 0xc0c0c0;
            TasWSheet.get_Range(Operators.ConcatenateObject("A6:P", dong), Missing.Value).Borders.LineStyle = 1;
            if (Operators.ConditionalCompareObjectGreater(dong, 7, false))
            {
                TasWSheet.get_Range(Operators.ConcatenateObject("A6:P", Operators.SubtractObject(dong, 1)), Missing.Value).Borders[XlBordersIndex.xlInsideHorizontal].LineStyle = 3;
            }
        }
        
        public static void TasStartExcel(string SheetName)
        {
            try
            {
                ExApp = new ApplicationClass();
                TasWBook = ExApp.Workbooks.Add(Missing.Value);
                TasWSheet = (Worksheet)ExApp.Worksheets[SheetName];
                TasWSheet.Name = SheetName;
                ExApp.Visible = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                Interaction.MsgBox("TasStartExcel: " + exception.Message, MsgBoxStyle.Critical, null);
                ProjectData.ClearProjectError();
            }
        }
       
        //ham tao detail tung nhan vien
       
       
        private static void XuatCT(string MaNV, int dong, int Dem, DateTime Startday, DateTime Endday, BindingSource bngSource)
        {
            BindingSource source = bngSource;

        }
        public void HeaderSumOT(DateTime TuNgay)
        {
            int num2 = 4;
            Worksheet tasWSheet = TasWSheet;
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 3)) + ":H" + Conversions.ToString((int)(num2 - 3)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 3)), Missing.Value).set_Value(Missing.Value, "OT SUMMARY - " + DateAndTime.MonthName(DateAndTime.Month(TuNgay), true) + "'" + Conversions.ToString(DateAndTime.Year(TuNgay)));
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 3)), Missing.Value).Font.Bold = true;
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 3)), Missing.Value).Font.Size = 12;
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 1)) + ":A" + Conversions.ToString(num2), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 1)), Missing.Value).set_Value(Missing.Value, "S.No");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["A", Missing.Value], null, "ColumnWidth", new object[] { 7 }, null, null, false, true);
            tasWSheet.get_Range("B" + Conversions.ToString((int)(num2 - 1)) + ":B" + Conversions.ToString(num2), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("B" + Conversions.ToString((int)(num2 - 1)), Missing.Value).set_Value(Missing.Value, "CODE");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["B", Missing.Value], null, "ColumnWidth", new object[] { 7 }, null, null, false, true);
            tasWSheet.get_Range("C" + Conversions.ToString((int)(num2 - 1)) + ":C" + Conversions.ToString(num2), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("C" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "DEPT.");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["C", Missing.Value], null, "ColumnWidth", new object[] { 10 }, null, null, false, true);
            tasWSheet.get_Range("D" + Conversions.ToString((int)(num2 - 1)) + ":D" + Conversions.ToString(num2), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("D" + Conversions.ToString((int)(num2 - 1)), Missing.Value).set_Value(Missing.Value, "NAME");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["D", Missing.Value], null, "ColumnWidth", new object[] { 20 }, null, null, false, true);
            tasWSheet.get_Range("E" + Conversions.ToString((int)(num2 - 1)) + ":E" + Conversions.ToString(num2), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("E" + Conversions.ToString((int)(num2 - 1)), Missing.Value).set_Value(Missing.Value, "No. of NightShift");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["E", Missing.Value], null, "ColumnWidth", new object[] { 10 }, null, null, false, true);
            tasWSheet.get_Range("F" + Conversions.ToString((int)(num2 - 1)) + ":G" + Conversions.ToString((int)(num2 - 1)), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("F" + Conversions.ToString((int)(num2 - 1)), Missing.Value).set_Value(Missing.Value, "OT hrs");
            tasWSheet.get_Range("F" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "Normal day");
            tasWSheet.get_Range("G" + Conversions.ToString(num2), Missing.Value).set_Value(Missing.Value, "W.off");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["F:G", Missing.Value], null, "ColumnWidth", new object[] { 8 }, null, null, false, true);
            tasWSheet.get_Range("H" + Conversions.ToString((int)(num2 - 1)) + ":H" + Conversions.ToString(num2), Missing.Value).Merge(Missing.Value);
            tasWSheet.get_Range("H" + Conversions.ToString((int)(num2 - 1)), Missing.Value).set_Value(Missing.Value, "HOLIDAYS");
            NewLateBinding.LateSetComplex(tasWSheet.Columns["H", Missing.Value], null, "ColumnWidth", new object[] { 10 }, null, null, false, true);
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 1)) + ":H" + Conversions.ToString(num2), Missing.Value).Font.Bold = true;
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 1)) + ":H" + Conversions.ToString(num2), Missing.Value).Font.Size = 10;
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 1)) + ":H" + Conversions.ToString(num2), Missing.Value).HorizontalAlignment = XlHAlign.xlHAlignCenter;
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 1)) + ":H" + Conversions.ToString(num2), Missing.Value).WrapText = 1;
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 1)) + ":H" + Conversions.ToString(num2), Missing.Value).Borders.LineStyle = 1;
            tasWSheet.get_Range("A" + Conversions.ToString((int)(num2 - 1)) + ":H" + Conversions.ToString(num2), Missing.Value).VerticalAlignment = XlVAlign.xlVAlignCenter;
            NewLateBinding.LateSetComplex(tasWSheet.Rows["4:4", Missing.Value], null, "RowHeight", new object[] { 0x18 }, null, null, false, true);

        }

    }
}
